
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <meta charset="UTF-8">
    <style>
        *{margin:0;padding:0}
        .demo-wrap{width: 400px;height: 50px;margin: 50px auto auto auto}
    </style>

    <!--<script src="./js/jquery-1.6.4.min.js"></script>-->
    <!--<script src="./js/Encryption.js"></script>-->
    <!--<script src="./js/RSA.js"></script>-->
    <!--<script src="./js/BigInt.js"></script>-->
    <!--<script src="./js/Barrett.js"></script>-->
    <!--<script src="./rollups/aes.js"></script>-->
    <script src="AES.js"></script>
    <script src="sha256.js"></script>
    <script src="ZeroPadding.js"></script>
    <script  src="base64.js"></script>
    <script src="http://passport.cnblogs.com/scripts/jsencrypt.min.js"></script>
</head>

<body>

<div class="demo-wrap">
    输入框：<input type="text" id="data-ipt" maxlength="1000000"/>
    <input type="button" value="提交" onclick="enAES();" />
    <br/>
    数据获得:
    <p id="decrypted"></p>
</div>

<script type="text/javascript">

    function enAES(){
        var keyRSA =  new JSEncrypt(); //生成RSA加密用的key
        var key  ="3333333333";//随机生成AES的key 和 ivrandomString()
        var iv   = "wwwwwee";
        var aKey = encryptedString(keyRSA, encodeURIComponent(key)); //RSA加密AES的key
        console.log(akey)
        var aIv = encryptedString(keyRSA, encodeURIComponent(iv)); //RSA加密AES的iv
        var inputData = document.getElementById("data-ipt").value; //获取输入框内容
        var miwen = getAesString(encodeURIComponent(inputData),key,iv); //AES加密输入框内容

        /** 调用后台： ajax */
        $.ajax({
            url: "/jiami/RSAAES",
            type: "post",
            data: {"miwen":miwen,"aKey":aKey,"aIv":aIv},
            cache: false,
            async : false,
            dataType: "json",
            success: function (data)
            {
                var decryptedStr = getDAesString(data,key,iv);
                document.getElementById("decrypted").innerHTML = decodeURIComponent(decryptedStr);
            },
            error:function (XMLHttpRequest, textStatus, errorThrown) {
                alert("与服务器连接失败！");
            }
        });
    }
</script>
</body>
</html>
